package com.xs.project.service.impl;

import com.xs.project.common.Result;
import com.xs.project.mapper.CompanyManagerMapper;
import com.xs.project.pojo.vo.CompanyReq;
import com.xs.project.pojo.vo.StuCompanyReq;
import com.xs.project.pojo.vo.resp.StuCompanyResp;
import com.xs.project.pojo.vo.resp.UserInfoAndCourse;
import com.xs.project.pojo.vo.resp.XcCourseResp;
import com.xs.project.pojo.vo.resp.XsCompany;
import com.xs.project.service.ICompanyManagerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class CompanyManagerServiceImpl implements ICompanyManagerService {
    @Resource
    private CompanyManagerMapper companyManagerMapper;
    @Override
    public Result<List<XsCompany>> selectCompanyList(CompanyReq request) {
        List<XsCompany> list = companyManagerMapper.selectCompanyList(request);
        long skipSize = (long) request.getPageSize() * (request.getPageNum() - 1); // 计算需要跳过的元素数量

        List<XsCompany> pageRes = list.stream()
                .skip(skipSize)
                .limit(request.getPageSize())
                .collect(Collectors.toList());
        return Result.success(pageRes,list.size());
    }

    @Override
    public Boolean updateCompanyList(XsCompany request) {
        companyManagerMapper.updateCompanyList(request);
        return true;
    }

    @Override
    public Boolean insertCompanyList(XsCompany request) {
        companyManagerMapper.insertCompanyList(request);
        return true;
    }

    @Override
    public Result<List<StuCompanyResp>> selectStuCompanyList(StuCompanyReq request) {
        List<StuCompanyResp> list = companyManagerMapper.selectStuCompanyList(request);
        long skipSize = (long) request.getPageSize() * (request.getPageNum() - 1); // 计算需要跳过的元素数量

        List<StuCompanyResp> pageRes = list.stream()
                .skip(skipSize)
                .limit(request.getPageSize())
                .collect(Collectors.toList());
        for (StuCompanyResp pageRe : pageRes) {
            if ("0".equals(pageRe.getType())){
                pageRe.setTypeStr("实习");
            }else {
                pageRe.setTypeStr("正式");
            }

        }
        return Result.success(pageRes,list.size());
    }

    @Override
    public Boolean updateStuCompanyList(StuCompanyResp request) {
        companyManagerMapper.updateStuCompanyList(request);
        return true;
    }

    @Override
    public Boolean insertStuCompanyList(StuCompanyResp request) {
        companyManagerMapper.insertStuCompanyList(request);
        return true;
    }
}
